package cn.sumpu.app.guoguojie.dao.impl;

import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.sumpu.app.guoguojie.dao.AuxProfilerDao;
import cn.sumpu.app.guoguojie.domain.AuxProfiler;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class AuxProfilerDaoImpl extends SqlSessionDaoSupport implements
		AuxProfilerDao {

	private final static Logger logger = LoggerFactory
			.getLogger(AuxProfilerDaoImpl.class);

	@Override
	public void insert(AuxProfiler auxProfiler) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("cn.sumpu.app.guoguojie.persistence.AuxProfilerMapper.insert",
							auxProfiler);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertAuxProfiler database failure.", e);
			}
			throw new AppBusinessException(
					"insertAuxProfiler database failure.", e);
		}
	}

	public void update(AuxProfiler auxProfiler) throws AppBusinessException {
		try {
			getSqlSession()
					.update("cn.sumpu.app.guoguojie.persistence.AuxProfilerMapper.update",
							auxProfiler);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("update database failure.", e);
			}
			throw new AppBusinessException("update database failure.", e);
		}

	}

	@Override
	public AuxProfiler getByUrl(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return (AuxProfiler) getSqlSession()
					.selectOne(
							"cn.sumpu.app.guoguojie.persistence.AuxProfilerMapper.getByUrl",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("query database failure.", e);
			}
			throw new AppBusinessException("query database failure.", e);
		}
	}

}
